package com.zqweb.gulimall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class MyThreadPoolConfig {
    @Bean
    // 自定义线程池，构建参数部分由配置属性读取类MyThreadPoolArgsProperties，读取核心配置文件设置的参数值来设置的
    public ThreadPoolExecutor myThreadPool(MyThreadPoolArgsProperties threadPoolArgsProperties){
        return new ThreadPoolExecutor(
                threadPoolArgsProperties.getCoreSize(), threadPoolArgsProperties.getMaxSize(),
                threadPoolArgsProperties.getKeepAliveTime(), TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(150000), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
